type WebpackConfig = import("webpack").Configuration;

export function getWebpackConfig(
  {
    entry,
    dist,
    filename,
    mode,
    libraryTarget,
  }: {
    entry: string;
    dist: string;
    filename: string;
    mode?: "none" | "development" | "production";
    libraryTarget?: "commonjs2" | "module";
  },
  options: Record<string, any> = {},
): WebpackConfig {
  return {
    target: "node",
    mode: mode || "none",
    entry,
    output: {
      path: dist,
      filename,
      libraryTarget: libraryTarget || "commonjs2",
    },
    resolve: {
      extensions: [".js"],
    },
    module: {
      rules: [],
    },
    ...options,
  };
}
